package com.ykt.converter;

import com.ykt.common.utils.UB;
import com.ykt.model.Category;
import com.ykt.vo.CategoryVo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author long.hua
 * @version 1.0.0
 * @since 2016-05-28 12:47
 */
public class CategoryConverter {


    public static CategoryVo convert(Category model){
        if(model == null){
            return null;
        }

        CategoryVo vo = new CategoryVo();
        BaseConverter.convert(vo, model);

        vo.setMarketId(UB.i(model.get(Category.market_id)));
        vo.setPid(UB.i(model.get(Category.pid)));
        vo.setIcon(model.getStr(Category.icon));
        vo.setCategoryId(UB.i(model.get(Category.id), -1));
        vo.setCategoryName(model.getStr(Category.name));
        vo.setCategoryIcon(model.getStr(Category.icon));

        return vo;
    }


    public static List<CategoryVo> convert(List<Category> models){
        if(models == null || models.isEmpty()){
            return null;
        }

        List<CategoryVo> vos = new ArrayList<>();

        for (Category model : models) {
            vos.add(convert(model));
        }

        return vos;
    }

}
